package com.ruoyi.web.controller.procurement;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.procurement.domain.PsGoods;
import com.ruoyi.procurement.service.IPsGoodsService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物品库存Controller
 * 
 * @author ruoyi
 * @date 2023-10-10
 */
@RestController
@RequestMapping("/procurement-system/goods")
public class PsGoodsController extends BaseController
{
    @Autowired
    private IPsGoodsService psGoodsService;

    /**
     * 查询物品库存列表
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:goods:list')")
    @GetMapping("/list")
    public TableDataInfo list(PsGoods psGoods)
    {
//        startPage();
        List<PsGoods> list = psGoodsService.selectPsGoodsList(psGoods);
        return getDataTable(list);
    }

    /**
     * 导出物品库存列表
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:goods:export')")
    @Log(title = "物品库存", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, PsGoods psGoods)
    {
        List<PsGoods> list = psGoodsService.selectPsGoodsList(psGoods);
        ExcelUtil<PsGoods> util = new ExcelUtil<PsGoods>(PsGoods.class);
        util.exportExcel(response, list, "物品库存数据");
    }

    /**
     * 获取物品库存详细信息
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:goods:query')")
    @GetMapping(value = "/{goodsId}")
    public AjaxResult getInfo(@PathVariable("goodsId") String goodsId)
    {
        return success(psGoodsService.selectPsGoodsByGoodsId(goodsId));
    }

    /**
     * 新增物品库存
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:goods:add')")
    @Log(title = "物品库存", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PsGoods psGoods)
    {
        return toAjax(psGoodsService.insertPsGoods(psGoods));
    }

    /**
     * 修改物品库存
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:goods:edit')")
    @Log(title = "物品库存", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PsGoods psGoods)
    {
        return toAjax(psGoodsService.updatePsGoods(psGoods));
    }

    /**
     * 删除物品库存
     */
    @PreAuthorize("@ss.hasPermi('procurement-system:goods:remove')")
    @Log(title = "物品库存", businessType = BusinessType.DELETE)
	@DeleteMapping("/{goodsIds}")
    public AjaxResult remove(@PathVariable String[] goodsIds)
    {
        return toAjax(psGoodsService.deletePsGoodsByGoodsIds(goodsIds));
    }
}
